<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>Linux 命令- wc | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>Linux 命令- wc</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux命令/">Linux命令</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数、字数、行数，并将统计结果显示输出。</p>
<h2 id="1．命令格式"><a href="#1．命令格式" class="headerlink" title="1．命令格式"></a>1．命令格式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">wc [选项]文件...</div></pre></td></tr></table></figure>
<h2 id="2．命令功能"><a href="#2．命令功能" class="headerlink" title="2．命令功能"></a>2．命令功能</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;统计指定文件中的字节数、字数、行数，并将统计结果显示输出。该命令统计指定文件中的字节数、字数、行数。如果没有给出文件名，则从标准输入读取。wc同时也给出所指定文件的总统计数。</p>
<h2 id="3．命令参数"><a href="#3．命令参数" class="headerlink" title="3．命令参数"></a>3．命令参数</h2><ul>
<li>-c 统计字节数。</li>
<li>-l 统计行数。</li>
<li>-m 统计字符数。这个标志不能与 -c 标志一起使用。</li>
<li>-w 统计字数。一个字被定义为由空白、跳格或换行字符分隔的字符串。</li>
<li>-L 打印最长行的长度。</li>
<li>-help 显示帮助信息</li>
<li>–version 显示版本信息</li>
</ul>
<h2 id="4．使用实例"><a href="#4．使用实例" class="headerlink" title="4．使用实例"></a>4．使用实例</h2><h3 id="实例1：查看文件的字节数、字数、行数"><a href="#实例1：查看文件的字节数、字数、行数" class="headerlink" title="实例1：查看文件的字节数、字数、行数"></a>实例1：查看文件的字节数、字数、行数</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">wc test.txt</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat test.txt </span></div><div class="line">hnlinux</div><div class="line">peida.cnblogs.com</div><div class="line">ubuntu</div><div class="line">ubuntu linux</div><div class="line">redhat</div><div class="line">Redhat</div><div class="line">linuxmint</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># wc test.txt</span></div><div class="line"> 7  8 70 test.txt</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># wc -l test.txt </span></div><div class="line">7 test.txt</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># wc -c test.txt </span></div><div class="line">70 test.txt</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># wc -w test.txt </span></div><div class="line">8 test.txt</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># wc -m test.txt </span></div><div class="line">70 test.txt</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># wc -L test.txt </span></div><div class="line">17 test.txt</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;7&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;8&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;70&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;test.txt</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;行数 单词数 字节数 文件名</p>
<h3 id="实例2：用wc命令怎么做到只打印统计数字不打印文件名"><a href="#实例2：用wc命令怎么做到只打印统计数字不打印文件名" class="headerlink" title="实例2：用wc命令怎么做到只打印统计数字不打印文件名"></a>实例2：用wc命令怎么做到只打印统计数字不打印文件名</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">wc -l test.txt</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># wc -l test.txt </span></div><div class="line">7 test.txt</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat test.txt |wc -l</span></div><div class="line">7[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用管道线，这在编写shell脚本时特别有用。</p>
<h3 id="实例3：用来统计当前目录下的文件数"><a href="#实例3：用来统计当前目录下的文件数" class="headerlink" title="实例3：用来统计当前目录下的文件数"></a>实例3：用来统计当前目录下的文件数</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ls -l | wc -l</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test6</span></div><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">总计 604</div><div class="line">---xr--r-- 1 root mail  302108 11-30 08:39 linklog.log</div><div class="line">---xr--r-- 1 mail users 302108 11-30 08:39 log2012.log</div><div class="line">-rw-r--r-- 1 mail users     61 11-30 08:39 log2013.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2014.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2015.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2016.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2017.log</div><div class="line">[root@localhost test6]<span class="comment"># ls -l | wc -l</span></div><div class="line">8</div><div class="line">[root@localhost test6]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;数量中包含当前目录</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/2. Linux 命令/42. Linux 命令- wc/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
